<?php $this->_extends('../_layouts/default_layout');?>
<?php $this->_block('contents');?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript">
$(function(){
	$("a[rel^='pretty_photo']").prettyPhoto({theme: 'facebook'});
	$(".message_picture").colorbox({maxHeight: "90%", maxWidth: "90%"});
	$(".message_template").change(function(){
		$.ajax({
			type: "GET",
			url: "<?=url('Services::EbayMessage/MessageTemplateAjax')?>&id=" + $(this).val(),
			dataType: "text",
			success:
				function(data)
				{
					$("#body").val(data);
				}
		});
	});
	$(".send_mail_btn").click(function(){
		$("#send_mail").show();
	});
	$(".send_message_btn").click(function(){
		if (! $("#body").val())
		{
			alert("邮件不能为空！！")
			return false;
		}
		$(this).attr('disabled', true);
		$(this).next().show();
		$("#sendmessage_form").submit();
	});
	var i = 1;
	$(".add_file_input").click(function(){
		if (i <= 5)
		{
			$("#file_input").append('<input type="file" name="picture' + i + '" style="width: 190px; margin-right: 30px;" />');
			i++;
		}
		else
		{
			alert('添加图片不能超过五个！');
			return false;
		}
	});
	$(".resend_btn").click(function(){
		if ( ! confirm('确定重新发送邮件？'))
		{
			return false;
		}
		$(this).next().show();
		$("#resend_message").find("input[name='send_id']").val($(this).prev().val()); 
		$("#resend_message").submit();
	});
	$(".show_send_history").toggle(function(){
		$("#send_history").show();
	},function(){
		$("#send_history").hide();
	});
});
</script>
<table width="100%">
<tr>
	<td width="70%" valign="top">
	<form action="<?=url('Services::EbayMessage/SendMessage')?>" method="post" id="sendmessage_form" enctype="Multipart/form-data">
		<table style="width: 100%;">
			<tr>
				<td colspan="2">
					<div>
						<strong>时间：</strong><?=$message['sender']?> 发送于 <?=$message['receive_time']?><br />
						<strong>主题：</strong><?=$message['subject']?>
					</div>
					<iframe style="width: 96%; height: 400px; border:1px solid #ccc;" src="<?=url('Services::EbayMessage/DetailBody') . '&id=' . $message['id']?>"></iframe>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<?if ($message['picture']):?>
					<div style="margin: 3px 0px">
						<span style="float: left; font-weight: bold;">邮件附件：</span>
						<?foreach($message['picture'] as $mp):?>
						<a style="border: 1px solid #aaaaaa; width: 50px; height: 50px; float: left; display: block; margin-right: 10px;" class="message_picture" href="<?=preg_replace('/\$_\d{1,2}.JPG/', '$_10.JPG', $mp['url'])?>" title="<?=$mp['name']?>">
							<img width="50px" height="50px" src="<?=$mp['url']?>"></img>
						</a>
						<?endforeach;?>
					</div>
					<?endif;?>
				</td>
			</tr>
			<?if ($message['response_enabled'] == 1):?>
			<tr>
				<td colspan="2"><input type="button" style="margin-top: 5px;" class="send_mail_btn button" value="回复" /></td>
			</tr>
			<tbody id="send_mail" style="display: none;">
			<tr>
				<td align="right" width="60px">TO：</td>
				<td><strong><?=$message['sender']?></strong></td>
			</tr>
			<tr>
				<td align="right">Subject：</td>
				<td><?=$message['subject']?></td>
			</tr>
			<tr>
				<td align="right">回复模板：</td>
				<td>
					<select class="message_template">
						<option value="0">--请选择--</option>
						<?foreach ($message_template as $mt):?>
						<option value="<?=$mt['id']?>"><?=$mt['name']?></option>
						<?endforeach;?>
					</select>
					<a class="add_file_input" style="margin-left: 50px;">添加图片</a>
				</td>
			</tr>
			<tr>
				<td></td>
				<td id="file_input"></td>
			</tr>
			<tr>
				<td align="right">Body：</td>
				<td>
					<div>
						<textarea rows="10" name="body" id="body" style="width: 96%"></textarea>
					</div>
				</td>
			</tr>
			<tr>
				<td align="right">From：</td>
				<td><strong><?=$message['recipient']?></strong></td>
			</tr>
			<tr>
				<td><input type="hidden" name="<?=Q::ini('unique_token_name')?>" value="<?=Helper_BSS_Normal::genToken()?>" /></td>
				<td>
					<input type="hidden" name="message_id" id="message_id" value="<?=$message['id']?>" />
					<input type="button" class="button send_message_btn" value="发送邮件"> <img src="<?=Q::ini('custom_system/base_url')?>img/loading.gif" style="display: none" />
				</td>
			</tr>
			</tbody>
			<?endif;?>
		</table>
	</form>
	</td>
	<td width="30%"  valign="top">
	<table width="100%">
		<tr>
			<td style="text-align: center">
				<table class="list_table" width="100%"><tr><th><?=!empty($message['shop_item_id']) ? ('ItemID（' . $message['shop_item_id'] . '）的') : ''?>上架产品信息</th></tr></table>
				<div style="overflow-y:auto;<?=((count($listing_item) > 5) ? 'height:190px;' : '')?>width:100%;">
				<table class="list_table" width="100%">
					<tr>
						<th>SKU</th>
						<th>价格</th>
					</tr>
					<?foreach ($listing_item as $li):?>
					<tr>
						<td align="left"><?=$li['sku']?>
							<?if ($li['pic_url']):?>
								<?$pretty_photo_number = 0;?>
								<?foreach ($li['pic_url'] as $pp):?>
								<a rel="pretty_photo[<?=$li['id']?>]" href="<?=$pp?>"><?if(!$pretty_photo_number):?><span class="img_icon"></span><?endif;?></a>
								<?$pretty_photo_number = 1;?>
								<?endforeach;?>
							<?endif;?>
						</td>
						<td><?=$li['currency_symbol'] . ' ' . $li['start_price']?></td>
					</tr>
					<?endforeach;?>
				</table>
				</div>
			</td>
		</tr>
		<tr><td>&nbsp;</td></tr>
		<tr>
			<td>
				<table class="list_table" width="100%">
					<tr>
						<th colspan="3"><?=!empty($message['external_message_id']) ? ('顾客（' . $message['sender'] . '）') : ''?>购买记录</th>
					</tr>
					<tr>
						<th>订单号</th>
						<th>金额</th>
						<th>下单时间</th>
					</tr>
					<?foreach ($order as $o):?>
					<tr>
						<td><a href="<?=url('Sales::Order/List', array('is_search' => 1, 'number' => $o['number']))?>" target="_blank"><?=$o['number']?></a></td>
						<td><?=$o['symbol']?><?=sprintf('%.2f', $o['amount'])?></td>
						<td><?=$o['sales_time']?></td>
					</tr>
					<?endforeach;?>
					<?if (!empty($message['external_message_id'])):?>
					<tr>
						<td colspan="3"><a href="<?=url('Sales::Order/List', array('is_search' => 1, 'shop_buyer_id' => $message['sender']))?>" target="_blank">查看所有记录</a></td>
					</tr>
					<?endif;?>
				</table>	
			</td>
		</tr>
		<tr><td>&nbsp;</td></tr>
		<tr>
			<td>
				<table class="list_table" width="100%">
					<tr>
						<th colspan="2"><?='顾客（' . $message['sender'] . '）'?>评价</th>
					</tr>
					<tr>
						<th align="center" width="30%">评价类型</th>
						<th align="center" width="70%">店铺评价</th>
					</tr>
					<?if (empty($feedback)): ?>
					<tr>
						<td colspan="2" align='center'><? echo "该用户还没进行评价！"; ?></td>
					</tr>
					<?else: ?>
					<?foreach ($feedback as $fb):?>
					<tr>
						<td align="left">
						<span class="<?=Helper_BSS_Normal::getIniOne('services_ebay_feedback_type', 'value', $fb['type'], 'icon_class')?>" title="<?=Helper_BSS_Normal::getIniOne('services_ebay_feedback_type', 'value', $fb['type'], 'name')?>"></span>
						<?=Helper_BSS_Normal::getIniOne('services_ebay_feedback_type', 'value', $fb['type'], 'name')?>
						</td>
						<td align="left"><?=$fb['content'] ?></td>
					</tr>
					<?endforeach; ?>
					<?endif; ?>
					<?if ( ! empty($feedback)): ?>
					<tr>
						<th colspan="2"><a href="<?=url('Services::Ebayfeedback/List', array('user' => $message['sender'])) ?>" target="_blank">显示所有</a></th>
					</tr>
					<?endif; ?>
				</table>
			</td>
		</tr>
		<tr><td>&nbsp;</td></tr>
		<tr>
			<td>
				<table class="list_table" width="100%">
					<tr>
						<th>该邮件回信历史</th>
					</tr>
					<?foreach ($send as $s):?>
					<tr>
						<td align="left">
							&nbsp;&nbsp;<strong>时间：</strong><?=$s['send_time']?>&nbsp;&nbsp;
							<strong>发送状态：</strong>
							<?=Helper_BSS_Normal::getIniOne('services_ebay_message_send_send_flag', 'value', $s['send_flag'], 'name')?>
							<br />
							&nbsp;&nbsp;<strong>回信人：</strong><?=$s['send_user_name']?>&nbsp;&nbsp;&nbsp;&nbsp;
							<?if ($s['send_flag'] == Q::ini('custom_flag/services_ebay_message_send_send_flag/failure/value')):?>
								<input type="hidden" value="<?=$s['id']?>" />
								<a href="javascript: void;" class="resend_btn">重新发送</a>
								<img src="<?=Q::ini('custom_system/base_url')?>img/loading.gif" style="display: none" />
							<?endif;?>
							<textarea rows="8" readonly="readonly" style="background: #F0F0F0; border-color: #B8B8B8; color: #444; width: 95%; margin-left: 2%"><?=$s['body']?></textarea>
							<br />
							<strong style="float: left; font-weight: bold; margin-left: 8px;">邮件附件：</strong>
							<?foreach($s['picture'] as $sp):?>
							<a style="border: 1px solid #aaaaaa; width: 50px; height: 50px; float: left; display: block; margin-right: 10px;" class="message_picture" href="<?=$sp['url']?>" title="<?=$sp['name']?>">
								<img width="50px"height="50px" src="<?=$sp['url']?>"></img>
							</a>
							<?endforeach;?>
						</td>
					</tr>
					<?endforeach;?>
					<tr>
						<th><a class="show_send_history" href="javascript: void(0);">显示所有回信历史</a></th>
					</tr>
					<tbody id="send_history" style="display: none; width=100%;">
					<?foreach ($send_history as $sh):?>
					<tr>
						<td align="left">
							&nbsp;&nbsp;<strong>时间：</strong><?=$sh['send_time']?>&nbsp;&nbsp;
							<strong>发送状态：</strong>
							<?=Helper_BSS_Normal::getIniOne('services_ebay_message_send_send_flag', 'value', $sh['send_flag'], 'name')?>
							<br />
							&nbsp;&nbsp;<strong>回信人：</strong><?=$sh['send_user_name']?>&nbsp;&nbsp;&nbsp;&nbsp;
							<textarea rows="8" readonly="readonly" style="background: #F0F0F0; border-color: #B8B8B8; color: #444; width: 95%; margin-left: 2%"><?=$sh['body']?></textarea>
							<br />
							<strong style="float: left; font-weight: bold; margin-left: 8px;">邮件附件：</strong>
							<?foreach($sh['picture'] as $shp):?>
							<a style="border: 1px solid #aaaaaa; width: 50px; height: 50px; float: left; display: block; margin-right: 10px;" class="message_picture" href="<?=$shp['url']?>" title="<?=$shp['name']?>">
								<img width="50px"height="50px" src="<?=$shp['url']?>"></img>
							</a>
							<?endforeach;?>
						</td>
					</tr>
					<?endforeach;?>
					</tbody>
				</table>	
			</td>
		</tr>
	</table>
	</td>
</tr>
</table>
<div style="display: none;">
<form method="post" action="<?=url('Services::EbayMessage/ResendMessage')?>" id="resend_message">
<input type="hidden" name="send_id" value="" />
<input type="hidden" name="<?=Q::ini('unique_token_name')?>" value="<?=Helper_BSS_Normal::genToken()?>" />
</form>
</div>
<?php $this->_endblock();?>